package com.example.common.utils

import com.blankj.utilcode.util.SPUtils
import dagger.Module
import dagger.hilt.InstallIn
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
object RetrofitUtils {
    fun getRetrofit(): Retrofit {
        val client= OkHttpClient.Builder()
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30, TimeUnit.SECONDS)
            .connectTimeout(30, TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor{
                val token = SPUtils.getInstance().getString("token")
                val request = it.request().newBuilder()
                .addHeader("Authori-zation", token)
                .addHeader("Content-Language", "zh_CN")
                .addHeader("platform", "ANDROID")
                .addHeader("source", "CLUB_APP")
                .addHeader("meid", "ai0d75be6be8db1f85ef1768a0157815ed")
                .addHeader("version", "1.1.5")
                .addHeader("phoneModel", "google_sdk_gphone64_x86_64")
                .build()
                it.proceed(request)
            }
            .build()

        val retrofit = Retrofit.Builder()
            .baseUrl(com.example.common.Constants.BASE_URL)//这里写接口地址
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return retrofit
    }
}